<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;
class Index extends Controller
{

  //登录
  public function admin()
  {
         if(!$_POST){
                return json(['msg'=>'请求发送','code'=>1,'data'=>'','status'=>1]);
          }
          $username=$_POST['username'];
          $password=$_POST['password'];
          $data=Db::table('Admin')->paginate($limit,false,['page'=>$page]);

          if(!$data){
                 return json(['msg'=>'登录失败','code'=>1,'data'=>'','status'=>1]);
          } 
                 return json(['msg'=>'登录成功','code'=>0,'data'=>$data,'status'=>0]);
  }
    public function index()
    {
          if(!$_GET){
          	    return json(['msg'=>'无此信息','code'=>1,'data'=>'','status'=>1]);
          }
          $page=$_GET['page'];
          $limit=$_GET['limit'];
          $data=Db::table('good')->paginate($limit,false,['page'=>$page]);

          if(!$data){
          	     return json(['msg'=>'查询是失败','code'=>1,'data'=>'','status'=>1]);
          } 
                 return json(['msg'=>'查询成功','code'=>0,'data'=>$data,'status'=>0]);
    }
    //删除
    public function del()
    {
         $id=Request::instance()->GET('id','');

         $where['id']=$id;
         $res=Db::table('good')->delete($id);

          if(!$res){
          	     return json(['msg'=>'删除失败','code'=>1,'data'=>'','status'=>1]);
          } 
                 return json(['msg'=>'删除成功','code'=>0,'data'=>$res,'status'=>0]);
    }
    //修改
    public function updat()
    {     $arr=input('get.');

          $data=model('Good')->updateGood($arr);
           if(!$data){
          	     return json(['msg'=>'修改失败','code'=>1,'data'=>'','status'=>1]);
          } 
                 return json(['msg'=>'修改成功','code'=>0,'data'=>$res,'status'=>0]);
    }
    //搜索
   public function search()
   {
       $search=input('get.');
       $page=input('get.page');
       $limit=input('get.limit');

       $res=model('Good')->getsearch($page,$limit,$search);
         if(!$res){
                 return json(['msg'=>'搜索失败','code'=>1,'data'=>'','status'=>1]);
          } 
                 return json(['msg'=>'搜索成功','code'=>0,'data'=>$res,'status'=>0]);

   }
}
